#include "usermgmt.h"
#include "ui_usermgmt.h"
#include "userauthhandler.h"
#include "QMessageBox"
#include "QtSql"

UserMgmt::UserMgmt(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::UserMgmt)
{
    ui->setupUi(this);
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("sql.db");
    db.open();

    QSqlQuery query ("select userId, userName from tabUsers");
    QSqlRecord record = query.record();
    int cols = record.count();

    while (query.next())
    {
        QVariant userId = query.value(0);
        QListWidgetItem* item = new QListWidgetItem();
        item->setData(Qt::UserRole + 0, userId);

        QString str;
        for (int i = 1; i < cols; i++)
        {
            if(!str.isEmpty())
                str.append(", ");

            str.append(query.value(i).toString());
        }
        item->setText(str);
        ui->listWidget222->addItem(item);
    }
}

UserMgmt::~UserMgmt()
{
    delete ui;
}

//        UserMgmt::fillUserList( void )
//        {
//            UserAuthHandler UserAuthHandlerTmp;
//            QList<UserDataModel> allUsers;
//
//            allUsers = UserAuthHandlerTmp.getAllUsers();
//        }



